Uec3.companyPermissionModule = Ext.extend(Ext.app.Module, {
    id: 'company_permission',
    objsCollection:new Ext.util.MixedCollection(true),
    getObjByKey:function(key){
		return this.objsCollection.get(key);
	},
    del:function(id){
		var grid=this.getObjByKey("grid");
		Ext.Msg.confirm('信息','确定要删除',function(btn){
		 	if(btn=='yes'){
		 		grid.loadMask.show();
			  	Ext.Ajax.request({
			  	url:Uec3.App.Constants.homeUrl+'/saleInvoice/base!delete.do',
			  	params:{'id':id},
        		success:function(response){
	        		var result=Ext.decode(response.responseText);
	        		if(result.success=='OK'){
	        			grid.getStore().reload();
	        		}else{
	        			Ext.Msg.alert('错误',result.success); 
	        		}
		        	grid.loadMask.hide();
        		},
        		failure:function(){
        			Ext.Msg.alert("信息",'网络问题');
        			grid.loadMask.hide();
        		}
			  	});
		    }
		});
	},
	view:function(id){
		var payInvoice_store=this.getObjByKey("store");
		var record=payInvoice_store.getById(id);
		var desktop =Uec3.App.getDesktop(); 
		desktop.launchWindowByParam("saleInvoice_operation",{id:id,winId:id}); 
	},
    getPanel:function(params) {
   	var module=this;
   	
	var tree = new Ext.tree.TreePanel({
        width: 400,
        height: 400,
        autoScroll: true,
        root: {
            id: 'department',
            expanded:true, 
            text: '公司'
        },
        loader: new Ext.tree.TreeLoader({
            dataUrl:Uec3.App.Constants.appUrl+'/companyPermission/base!treeLoader.do',
            listeners:{
            	'loadexception':function(tl,node,response){
            		Ext.Msg.alert("错误","加载失败,请重新加载!");
            	}
            }
        }),
        fbar: [{
            text: 'Reload root',
            handler: function(){
                tree.getRootNode().reload();
            }
        }],
        listeners:{
        	'click':function(node,e){
        		if(node.leaf&&node.leaf==true){
        					
        		}
        	}
        }
        
    });
    //tree.root.expand(false,false);
	//new Ext.tree.TreeSorter(tree, {folderSort:true});

	
	//爱好分组
	var checkboxGroup =null;
	
	var checkbox_store = new Ext.data.JsonStore({
		proxy : new Ext.data.HttpProxy({
			url : Uec3.App.Constants.homeUrl+ '/companyPermission/base!getRoleList.do'
		}),
		reader : new Ext.data.JsonReader({
			root:'root',totalProperty: "totalProperty"},
			[
			{name : 'id',type:'int'},
			{name : 'name',type:'string'},
			{name : 'companyId',type:'string'}
		]),
		listeners:{
			'load':function(store,records,options){

				var checks=[];
				Ext.each(records,function(record,i){
					var chkHobby= new Ext.form.Checkbox({
						name: "roleCheck",
						inputValue: record.data.id,
						boxLabel: record.data.name
					});
					checks.push(chkHobby);
				});
				checkboxGroup = new Ext.form.CheckboxGroup({
					name: "hobby",
					items: checks,
					width: 300
				});
			}
		}
	});
	checkbox_store.load();
	var panel=new Ext.Panel({
	    layout: 'hbox',
	    items: [tree]
	});
	/*{
	        region: 'center',
	        xtype: 'panel',
	        items: [checkboxGroup]
	    }*/
	return panel;
	},
	initEvent:function(){
		var module=this;
		var win=module.getObjByKey("win");
		win.on('show',function(){
			this.getObjByKey("store").load();
		},module,{single:true});
	},
   createWindow : function(params){
   	  var windowId=this.id;
   	  if(params&&params.winId){
   	  	windowId+="_"+params.winId;
   	  }
      var desktop = Uec3.App.getDesktop();   
      var win = desktop.getWindowByUecId(windowId);
      if(!win){ 
      	 var module=this;
         win = desktop.createWindow({
            uecId: windowId,
            width: 800,
            height: 500,
            title:'收款列表',
            iconCls: 'acc-icon',
            shim: false,
            moduleObj:module,
            constrainHeader: true,
            maximizable: true,
            layout: "fit", 
            items:[params=='undefined'?module.getPanel():module.getPanel(params)],
            listeners:{
            	'resize':function(win,width,height){
            		var top=this.items.get(0).items.first();
            		var grid=this.items.get(0).items.last();
            		var winMinWidth=900;
            		var winMinHeight=440;
            		if(width<winMinWidth||height<winMinHeight){
            			win.setWidth(winMinWidth);
            			win.setHeight(winMinHeight);
            			grid.setHeight(winMinHeight-110);
            		}else{
            			grid.setHeight(height-110);
            		}
            	}
            }
         });
         module.objsCollection.add("win",win);
         //module.initEvent();
      } 
      win.show();
   }
	});
